package com.example.mybatis.my.shop.controller;

import com.example.mybatis.my.shop.service.TbUserService;
import com.example.mybatis.my.shop.service.impl.TbUserServiceImpl;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "/deleteAll")
public class UserDeleteAllController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String ids = req.getParameter("ids");
        String[] split = StringUtils.split(ids, ",");
        TbUserService tbUserService = new TbUserServiceImpl();
        int re = tbUserService.deleteAllById(split);
        if(re>0){
            req.setAttribute("message","删除成功");
        }else{
            req.setAttribute("message","删除失败");
        }
        req.getRequestDispatcher("/userList").forward(req,resp);
    }
}
